package phantri.uit.menunhahang;

import org.ksoap2.SoapEnvelope;
//import org.ksoap2.SoapFault;
//import org.ksoap2.serialization.Marshal;
import org.ksoap2.serialization.PropertyInfo;
import org.ksoap2.serialization.SoapObject;
//import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;

import phantri.uit.menunhahang.Param;
//import phantri.uit.menunhahang.MenuCalculate;

public class DachonRequest {
	private static String METHOD_NAME = "DachonRequest";
	private static String NAMESPACE = "http://tempuri.org/";
	private static String SOAP_ACTION = NAMESPACE + METHOD_NAME;
	private static final String URL = "http://10.0.2.2/MenuServices/Service1.asmx";

	private static final String sDACHON_ID = "sID_DC";
	//private static final String sMONAN_ID = "sID_MA";
	//private static final String sDOUONG_ID = "sID_DU";
	private static final String sTEN_DC = "sTen_DC";
	private static final String sGIA_DC = "sGia_DC";
	private static final String sSOLUONG_DC = "sSoluong_DC";
	private static final String sTHANHTIEN_DC = "sThanhtien_DC";
	
	public void requestDachon(int dachonid, String tendc, int giadc,
			int thanhtiendc, int soluongdc) throws Exception {

		Param p_dachonid = new Param(sDACHON_ID, dachonid);
		Param p_tendc = new Param(sTEN_DC, tendc);
		Param p_giadc = new Param(sGIA_DC, giadc);
		Param p_soluongdc = new Param(sSOLUONG_DC, soluongdc);
		Param p_thanhtiendc = new Param(sTHANHTIEN_DC, thanhtiendc);		
		try {
			Param[] params = new Param[5];
			params[0] = p_dachonid;
			params[1] = p_tendc;
			params[2] = p_giadc;
			params[3] = p_soluongdc;
			params[4] = p_thanhtiendc;
			SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
			SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
					SoapEnvelope.VER11);
			envelope.dotNet = true;
			HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
			for (Param p : params) {
				setParam(request, p.name, p.value, p.value.getClass());
			}
			envelope.setOutputSoapObject(request);
			androidHttpTransport.call(SOAP_ACTION, envelope);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	private void setParam(SoapObject request, String name, Object value,
			Class<?> type) {
		PropertyInfo pi = new PropertyInfo();
		pi.setName(name);
		pi.setValue(value);
		if (type != null) {
			pi.setType(type);
		}
		request.addProperty(pi);
	}
}